from pydantic_settings import BaseSettings
from typing import Dict, Optional
import os

class Settings(BaseSettings):
    # 代理服务配置
    proxy_host: str = "0.0.0.0"
    proxy_port: int = 7777
    
    # HTTPS配置
    enable_https: bool = False  # 使用 Nginx 反向代理时，设置为 False
    ssl_certfile: Optional[str] = "/etc/nginx/ssl/ragrag.top.crt"  # SSL证书文件路径
    ssl_keyfile: Optional[str] = "/etc/nginx/ssl/ragrag.top.key"   # SSL私钥文件路径
    ssl_ca_certs: Optional[str] = None  # CA证书文件路径（可选）
    
    # 支持的后端服务配置（仅配置base_url，API密钥由调用方传入）
    backends: Dict[str, Dict[str, str]] = {
        "openai": {
            "base_url": "https://api.openai.com/v1",
            "auth_header": "authorization",  # Bearer Token
            "auth_prefix": "Bearer "
        },
        "azure": {
            "base_url": os.getenv("AZURE_OPENAI_ENDPOINT", "https://your-resource.openai.azure.com/openai/deployments/your-deployment"),
            "auth_header": "api-key",  # Azure API Key
            "auth_prefix": ""
        },
        "claude": {
            "base_url": "https://api.anthropic.com/v1",
            "auth_header": "x-api-key",  # Anthropic API Key
            "auth_prefix": ""
        },
        "deepseek": {
            "base_url": "https://api.deepseek.com/v1",
            "auth_header": "authorization",  # Bearer Token
            "auth_prefix": "Bearer "
        },
        "moonshot": {
            "base_url": "https://api.moonshot.cn/v1",
            "auth_header": "authorization",  # Bearer Token
            "auth_prefix": "Bearer "
        }
    }
    
    # 超时配置
    request_timeout: int = 60
    
    # 日志配置
    log_level: str = "INFO"
    
    # 忽略特定的SSL警告日志
    ignore_ssl_warnings: bool = True
    
    # 连接超时配置
    ssl_close_timeout: float = 2.0  # SSL关闭超时时间（秒）
    
    model_config = {
        "env_file": ".env",
        "extra": "allow"
    }

# 全局配置实例
settings = Settings() 